package com.liu.text;

import com.liu.mappers.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;

public class mybatisUtils {
    public static void main(String[] args) throws IOException, SQLException {
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory build = sqlSessionFactoryBuilder.build(resourceAsStream);
        SqlSession sqlSession = build.openSession();
        Connection connection = sqlSession.getConnection();
        connection.setAutoCommit(true);
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        System.out.println(mapper.allStudent());
        System.out.println(mapper.allStudent());
    }
}
